package cn.source.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.system.domain.SchoolYearAdmission;
import cn.source.system.service.ISchoolYearAdmissionService;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.common.core.page.TableDataInfo;

/**
 * 年度学校录取情况Controller
 * 
 * @author sourcebyte.vip
 * @date 2024-02-20
 */
@RestController
@RequestMapping("/system/admission")
public class SchoolYearAdmissionController extends BaseController
{
    @Autowired
    private ISchoolYearAdmissionService schoolYearAdmissionService;

    /**
     * 查询年度学校录取情况列表
     */
    @PreAuthorize("@ss.hasPermi('system:admission:list')")
    @GetMapping("/list")
    public TableDataInfo list(SchoolYearAdmission schoolYearAdmission)
    {
        startPage();
        List<SchoolYearAdmission> list = schoolYearAdmissionService.selectSchoolYearAdmissionList(schoolYearAdmission);
        return getDataTable(list);
    }

    /**
     * 导出年度学校录取情况列表
     */
    @PreAuthorize("@ss.hasPermi('system:admission:export')")
    @Log(title = "年度学校录取情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SchoolYearAdmission schoolYearAdmission)
    {
        List<SchoolYearAdmission> list = schoolYearAdmissionService.selectSchoolYearAdmissionList(schoolYearAdmission);
        ExcelUtil<SchoolYearAdmission> util = new ExcelUtil<SchoolYearAdmission>(SchoolYearAdmission.class);
        util.exportExcel(response, list, "年度学校录取情况数据");
    }

    /**
     * 获取年度学校录取情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:admission:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(schoolYearAdmissionService.selectSchoolYearAdmissionById(id));
    }
    
    /**
     * 新增年度学校录取情况
     */
    @PreAuthorize("@ss.hasPermi('system:admission:add')")
    @Log(title = "年度学校录取情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SchoolYearAdmission schoolYearAdmission)
    {
        return toAjax(schoolYearAdmissionService.insertSchoolYearAdmission(schoolYearAdmission));
    }

    /**
     * 新增年度学校录取情况
     */
    //@PreAuthorize("@ss.hasPermi('system:admission:query')")
    //@Log(title = "年度学校录取情况", businessType = BusinessType.INSERT)
    @GetMapping("/imp")
    public AjaxResult imp(String filePath,String dataType)
    {
    	if(filePath==null||filePath.equals("")) return AjaxResult.error("请选择上传的文件");
    	if(dataType==null||dataType.equals("")) return AjaxResult.error("请选择上传的数据类型");
    	filePath=filePath.replaceAll("/profile/", "d:/source-vue/static/uploadPath/");
    	if(dataType.equals("1")) {
    		return AjaxResult.success(schoolYearAdmissionService.imp(filePath,dataType)); 
		}else if(dataType.equals("2")) {
			return AjaxResult.success(schoolYearAdmissionService.impGradeDoc(filePath,dataType));
		}else if(dataType.equals("4")) {//招生计划2024
			return AjaxResult.success(schoolYearAdmissionService.impPlan2024(filePath,dataType));
		}else if(dataType.equals("5")) {//专科招生计划
			//return AjaxResult.success(schoolYearAdmissionService.impPlanZk(filePath,dataType));
			return AjaxResult.success(schoolYearAdmissionService.impPlan2024(filePath,dataType));
		}else if(dataType.equals("6")) {
    		return AjaxResult.success(schoolYearAdmissionService.impZk(filePath,dataType)); 
		}else if(dataType.equals("7")) {
    		return AjaxResult.success(schoolYearAdmissionService.impZk2023(filePath,dataType)); 
		}else if(dataType.equals("8")) {
    		return AjaxResult.success(schoolYearAdmissionService.imp2023(filePath,dataType)); 
		}else if(dataType.equals("9")) {//2024年本科导入
            return AjaxResult.success(schoolYearAdmissionService.imp2024(filePath,dataType));
        }else {
			return AjaxResult.success(schoolYearAdmissionService.impPlan(filePath,dataType));
		}
    	
        
    }
    
    @GetMapping("/fixData")
    public AjaxResult fixData()
    {
    	
    	
			return AjaxResult.success(schoolYearAdmissionService.fixData());
    	
        
    }

    /**
     * 修改年度学校录取情况
     */
    @PreAuthorize("@ss.hasPermi('system:admission:edit')")
    @Log(title = "年度学校录取情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SchoolYearAdmission schoolYearAdmission)
    {
        return toAjax(schoolYearAdmissionService.updateSchoolYearAdmission(schoolYearAdmission));
    }

    /**
     * 删除年度学校录取情况
     */
    @PreAuthorize("@ss.hasPermi('system:admission:remove')")
    @Log(title = "年度学校录取情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(schoolYearAdmissionService.deleteSchoolYearAdmissionByIds(ids));
    }
}
